package com.Factory;


import com.Result.FriendApplyResult;
import com.entity.FriendApply;
import com.entity.User;
import com.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class FriendApplyResultFactory {
    @Autowired
    private UserMapper userMapper;

    public FriendApplyResult newFriendApplyResult(FriendApply friendApply) {
        FriendApplyResult friendApplyResult = new FriendApplyResult();
        BeanUtils.copyProperties(friendApply, friendApplyResult);
        User user1 = this.userMapper.selectById(friendApply.getUserId1());
        User user2 = this.userMapper.selectById(friendApply.getUserId2());
        friendApplyResult.setUser1Name(user1.getName());
        friendApplyResult.setUser2Name(user2.getName());
        switch(friendApply.getStatus()) {
            case(0):
                friendApplyResult.setStatus("待处理");
                break;
            case(1):
                friendApplyResult.setStatus("已同意");
                break;
            case(2):
                friendApplyResult.setStatus("已拒绝");
                break;
            case(3):
                friendApplyResult.setStatus("已失效");
        }
        return friendApplyResult;
    }
}
